<template>
	<el-date-picker
      v-model="s_e"
      :type="type"
      align="right"
      unlink-panels
      :value-format="valueFormat"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      @change="ccc"
      :picker-options="pickerOptions">
    </el-date-picker>
</template>

<script>

import { mapGetters } from 'vuex';

export default {
	name: 'daterange',
		data () {
		return {
			s_e : this.se,

		  	pickerOptions: {
	          shortcuts: [{
	            text: '昨天',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
	              end.setTime(end.getTime() - 3600 * 1000 * 24 * 1);
	              picker.$emit('pick', [start, end]);
	            }
	          },{
	            text: '前天',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 2);
	              end.setTime(end.getTime() - 3600 * 1000 * 24 * 2);
	              picker.$emit('pick', [start, end]);
	            }
	          },{
	            text: '最近一周',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近一个月',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近三个月',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
	              picker.$emit('pick', [start, end]);
	            }
	          }, {
	            text: '最近半年',
	            onClick(picker) {
	              const end = new Date();
	              const start = new Date();
	              start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
	              picker.$emit('pick', [start, end]);
	            }
	          }],

	        }
		}
	},

	components: {

		
	},

	props: {
	  	se : Array,
	  	type : String,
	},

	computed : {
		...mapGetters([
			
		]),

		valueFormat () {
			if(this.type == 'datetimerange'){
				return 'yyyy-MM-dd HH:mm:ss';
			}else if(this.type == 'daterange'){
				return 'yyyy-MM-dd';
			}
			return '';
		},
	},

	methods : {
		ccc (val) {
			console.log(val);
			this.$emit('update:se', val);
		}
	},

	watch:{
	    
	},

	mounted () {
		
		
	},

}
</script>

<style scoped>

</style>
